const { readFile, writeFile,eraseFile } = require("../common/common.js");
const {
  DATA_PATH,
  REPORT_PATH,
} = require("../config/config.default.js");
const err = require("../constant/err.type.js");
const path = require("path");
const Router = require("koa-router");
const router = new Router();

const {saveLink,createLink,eraseLink,getLinks,createWork,eraseWork} = require("../controller/links.controller.js");
const {saveNode,createNode,eraseNode,getNodes,batchAddNodes} = require("../controller/nodes.controller.js");
const {saveOptical,createOptical,batchAddOptical,eraseOptical,getOpticals} = require("../controller/opticals.controller.js");
const {getConfig,saveConfig} = require("../controller/configs.controller.js");
const {getGaojing,updateJson,changeColor} = require("../common/common.js")
const {getOptical} = require("../services/opticals.service.js")
const {saveLinks,getLinkByName} = require("../services/links.service.js")
const {saveBox,createBox,batchAddBoxes,eraseBox,getBoxes,getBoxById} = require("../controller/boxes.controller.js");
const {saveDetail,createDetail,batchAddDetails,getDetails,eraseDetail} = require("../controller/details.controller.js");
const {saveGaojing,getGaojingById,getGaojingList} = require("../controller/gaojing.controller.js");
const {jsonImportOpticals,jsonEraseNodeJs,setAlarm,jiechu,dingwei,jsonCreateLine,lineEraseNode,lineEraseLink,hitLine,setShowName,autoGzgj,clearGzcx,createGzcx,updateJsonFile,jsonCreateBOX,jsonEraseBOX,saveBDZ,jsonCreateBDZ,jsonEraseAllStation} = require("../controller/ue.controller.js");
const {getFields,saveField,eraseFields} = require("../controller/fields.controller.js");
const {saveStation,batchAddStation,getStations,eraseAllStation,getStationByID} = require("../controller/stations.controller.js");
const { eraseStations } = require("../services/stations.service.js");
const {logger} = require("../middleware/log4.middleware.js")
router.get("/admin",async (ctx,next) => {
  await ctx.render("admin.html")
})
router.get("/zcgl",async (ctx,next) => {
  await ctx.render("occ.html");
})
router.get("/llgl",async (ctx,next) => {
  await ctx.render("llgl.html");
})
router.get("/btgdj",async(ctx,next) => {
  await ctx.render("btgdj.html")
})
router.get("/gllist",async (ctx,next) =>{
  await ctx.render("gllist.html")
})
router.get("/line",async (ctx,next) => {
  await ctx.render("line.html");
})
router.get("/mnyx",async (ctx,next) => {
  await ctx.render("mnyx.html")
})
router.get("/gzgj",async (ctx,next) => {
  await ctx.render("gzgj.html")
})
router.get("/gjls",async (ctx,next) => {
  await ctx.render("gjls.html")
})
router.get("/gzjc",async (ctx,next) => {
  await ctx.render("gzjc.html")
})
router.get("/mnyxed",async (ctx,next) => {
  await ctx.render("mnyxed.html");
})
router.get("/mnyxing",async (ctx,next) => {
  await ctx.render("mnyxing.html");
})
//告警详情
router.get("/gaojingdetail",async (ctx,next) => {
  await ctx.render("detail.html")
})
//接头盒详情
router.get("/jth",async (ctx,next) => {
  await ctx.render("jth.html")
})
router.get("/bdz",async (ctx,next) => {
  await ctx.render("bdz.html");
})



//获取字段列表
router.post("/getFields",getFields);
//保存字段列表
router.post("/saveFields",saveField);

//获取线路信息
router.post("/getLinks",logger,getLinks);
//创建线路
router.post("/createLink",logger,createLink);
//编辑线路
router.post("/modifyLink",logger,saveLink);
//删除线路
router.post("/eraseLink",logger,eraseLink);
//创建工作
router.post("/createWork",logger,createWork);
//删除工作
router.post("/eraseWork",eraseWork);
//创建结点
router.post("/createNode",createNode);
//导入节点
router.post("/importNodes",batchAddNodes);
//获取节点
router.post("/getNodes",getNodes);
//编辑节点
router.post("/modifyNode",saveNode);
//删除节点
router.post("/eraseNode",eraseNode);
//获取坐标信息
router.post("/getOpticals",getOpticals);
//编辑坐标信息
router.post("/modifyOptical",saveOptical);
//导入坐标信息
router.post("/importOpticals",batchAddOptical);
//删除坐标信息
router.post("/eraseOptical",eraseOptical);
//创建坐标信息
router.post("/createOptical",createOptical);
//获取配置
router.post("/getConfig",getConfig);
//保存配置
router.post("/saveConfig",saveConfig)
//批量保存接头盒
router.post("/importBoxes",batchAddBoxes);
//清除接头盒
router.post("/eraseBox",eraseBox);
//查询接头盒
router.post("/getBoxes",getBoxes);
//根据ID查询接头盒
router.post("/getBoxById",getBoxById);
//批量添加详情
router.post("/importDetails",batchAddDetails);
//保存详情
router.post("/saveDetail",saveDetail);
//删除详情
router.post("/eraseDetail",eraseDetail);
//查询详情
router.post("/getDetails",getDetails);
//保存告警
router.post("/saveGaojing",saveGaojing);
//查询告警列表
router.post("/getGaojingList",getGaojingList);
//查询指定ID的告警信息
router.post("/getGaojing",getGaojingById);
//解除告警
router.post("/secureGaojing",saveGaojing);
//查询变电站
router.post("/getStations",getStations);
//保存变电站
router.post("/saveStation",saveStation);
//批量创建变电站
router.post("/importBdz",batchAddStation)
//删除变电站
router.post("/eraseStations",eraseStations);
/* 
JSON操作
*/
//模拟设置告警
router.post("/setAlarm",setAlarm);
//模拟解除告警
router.post("/jiechu",jiechu);
//导入节点时，创建Js_node.json
router.post("/jsonImportOpticals",jsonImportOpticals);
 //删除指定JS_Node.json文件
router.post("/jsonEraseNodeJs",jsonEraseNodeJs);
//故障定位 
router.post("/dingwei",dingwei);
//在Js_POI.json创建line
router.post("/jsonCreateLine",jsonCreateLine);
//删除坐标信息时，修改POI
router.post("/lineEraseNode",lineEraseNode);
//删除线时，修改POI
router.post("/lineEraseLink",lineEraseLink);
//gllist页面点击线路修改visible和click属性
router.post("/hitLine",hitLine);
//设置poi.josn中的show_name
router.post("/setShowName",setShowName);
//接口 设置告警
router.post("/api/gzgj",autoGzgj);
//告警重现
router.post("/createGzcx",createGzcx);
//清除告警重现
router.post("/clearGzcx",clearGzcx);
//刷新文件
router.post("/updateJsonFile",updateJsonFile)
//创建接头盒时创建POI.json
router.post("/jsonCreateBOX",jsonCreateBOX);
//删除接头盒时删除POI.json
router.post("/jsonEraseBOX",jsonEraseBOX);
//创建变电站时创建POI.json
router.post("/jsonCreateBDZ",jsonCreateBDZ);
//查找指定变电站信息
router.post("/getStationByID",getStationByID);
//删除变电站时删除POI.json
router.post("/jsonEraseBDZ",jsonEraseBOX);
//保存变电站
router.post("/saveBDZ",saveBDZ);
//删除所有变电站
router.post("/eraseAllStation",eraseAllStation);
//json中删除所有的变电站
router.post("/jsonEraseAllStation",jsonEraseAllStation);
//暴露路由
module.exports = router;
